import java.io.Serializable;


// implements the base class for the patterns
public class PLFeature implements Serializable {
	private static final long serialVersionUID = 1L;

	private String mName = null;

	// remember one PL feature is for one type of query responses
	protected PLAttrib mAttribute =null;
		
	public PLFeature() {	}
	public PLFeature(String name) { mName = name;}

	public float BuildResponse(PLShape query, PLOutShape  outResponse) { return 0f;}	
	
	// the resulting float value reflects the confidence in response, 
	// if the response perfectly satisfies the pattern, 1 is returned, values less than 1 reflect 
	// decrease in confidence in the response.
	// if the confidence is too low, the pattern also returns a new shape that better fits the pattern.
	public float ValidateResponse(PLShape query, PLShape response, PLOutShape  outBetterMatch) {return 0f;}

	public float ImproveResponse(PLShape query, PLOutShape outResponse, PLShape  betterMatch) {return 0f;}

	// used the shape to update the attributes 
	public void UpdateAttributes(PLShape query, PLShape response){}

	public void SetName(String name) {mName = name;}
	public String GetName() {return mName;}

	// ensure that all queries to a particular feature have the same query response type
	public PLAttrib GetAttribByType(PLShape.ShapeIdT qId, PLShape.ShapeIdT rId) {
		if (mAttribute == null) {
			mAttribute = PLAttrib.GetAttribByType(qId, rId);
		}
		return mAttribute;
	}
	
	public static PLFeature GetFeatureByName(String name) {
		int nameCode = name.hashCode();
		
		if (nameCode == "Line".hashCode()) {
			return new PLFeatureLine();
		} else if (nameCode == "Random".hashCode()) {
			return null;//new PLFeatureRandom();
		} else {
			PLDebug.Err("Pattern %s unknown", name);
		}

		return null;
	}

	// STATIC methods

	// returns all the patterns implemented
	public static PLFeature[] GetAllFeatures()  {
		PLFeature[] mFeatures = new PLFeature[1];
		mFeatures[0] = new PLFeatureLine();
		//mFeatures[1] = new PLFeatureRandom();
	
		return mFeatures;
	}

	public static String[] GetAllFeatureNames() {
		String[] mFeatures = {"Line", "Random"};
		return mFeatures;
	}	
}
